﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.workPlan
{
    public partial class ListWorkPlanYSH : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                    int user_depid = 0;
                    if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_depid"].ToString()))
                    {
                        user_depid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_depid"].ToString());
                    }

                    Bind(roles_id, user_depid, user_id);

                }

            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_look")
            {
                Response.Redirect("WorkPlanLook.aspx?workplan_id=" + e.CommandArgument);
            }
           
        }


        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                int user_depid = 0;
                if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_depid"].ToString()))
                {
                    user_depid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_depid"].ToString());
                }

                Bind(roles_id, user_depid, user_id);

            }
        }

        private void Bind(int roles_id, int user_depid, int user_id)
        {
            Maticsoft.BLL.workplan wm = new Maticsoft.BLL.workplan();
            DataSet ds = null;

            if (roles_id == 1023)
            {
                //基层员工
                ds = wm.GetListByUserWorkPlan(" submit_uid= " + user_id);
            }
            if (roles_id == 1024)
            {
                //班长
                ds = wm.GetListByUserWorkPlan(" (check_step='绩效专责审核' or check_step='审核完成' or submit_uid=" + user_id + ") and user_depid= " + user_depid);

            }
            if (roles_id == 1025)
            {
                //绩效专责
                ds = wm.GetListByUserWorkPlan(" (check_step='部门经理审核' or check_step='审核完成') and user_depid= " + user_depid);

            }
            if (roles_id == 1026)
            {
                //部门经理
                ds = wm.GetListByUserWorkPlan(" check_step='审核完成' and user_depid= " + user_depid);
            }

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

        }
    }
}